// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
const eve = db.collection('eve')
const _ = db.command
// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  var start_time_date = new Date(event.start_time_date);
  var end_time_date = new Date(event.end_time_date);
  if (event.check_result == 0) {
    db.collection('eve').doc(event._id).update({
      data: {
        name: event.name,
        addr: event.addr,
        max_num: Number(event.max_num),
        start_time: start_time_date,
        end_time: end_time_date,
        qqgroup: event.qqgroup,
        des: event.des,
        pic: event.tmpUrlArr,
      },
      success: function(res) {
        console.log(res.data)
      }
    })
  } else if (event.check_result == 1) {
    db.collection('eve').doc(event._id).update({
      data: {
        name: event.name,
        good_name: event.good_name,
        good_price: Number(event.good_price),
        qqwx: event.qqwx,
        des: event.des,
        pic: event.tmpUrlArr,
      },
      success: function(res) {
        console.log(res.data)
      }
    })
  } else if (event.check_result == 2) {
    db.collection('eve').doc(event._id).update({
      data: {
        name: event.name,
        addr: event.addr,
        good_name: event.good_name,
        qqwx: event.qqwx,
        des: event.des,
        pic: event.tmpUrlArr,
      },
      success: function(res) {
        console.log(res.data)
      }
    })
  } else {
    wx.showToast({ title: '创修改活动失败！', icon: 'none' });
  }
}